package com.icezzz.circle_paint;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

public class MyFrame extends JFrame {
    /**
     * 序列化
     */
    private static final long serialVersionUID = 5456284374661877331L;

    @Override
    public void paint(Graphics g) {
        Graphics2D gg = (Graphics2D) g;
        gg.translate(300, 300);
        int xx = 500;
        int yy = 500;
        for (int i = 0; i < 10000; i++) {
            double theta = 2 * Math.PI / 90;
            Color c = ccc(i);
            gg.setColor(c);
            gg.rotate(theta, 750, 330);
            int x = (int) (Math.cos(i) * xx);
            int y = (int) (Math.sin(i) * yy);
            gg.fillRect(x, y, 1, 1);
        }
        gg.translate(-700, 300);
        for (int i = 0; i < 10000; i++) {
            double theta = 2 * Math.PI / 90;
            Color c = ccc(i);
            gg.setColor(c);
            gg.drawOval(500, 200, 500, 260);
            gg.rotate(theta, 750, 330);
        }

    }

    private Color ccc(int index) {
        List<Color> list = new ArrayList<Color>();
        int[] cc = new int[3];
        cc = new int[] { 255, 0, 0 };
        int flag = 1;
        int addNum = 127;
        int size = 12;
        int indexNum = 2;
        for (int i = 0; i < size; i++) {
            if (i % 4 == 0 || i % 4 == 1) {
                flag = 1;
            } else {
                flag = -1;
            }
            if (i % 2 == 0) {
                indexNum--;
            }
            if (indexNum < 0) {
                indexNum = 2;
            }
            cc[indexNum] += flag * addNum;
            if (cc[indexNum] == 128 || cc[indexNum] == 1) {
                cc[indexNum]--;
            }
            if (cc[indexNum] == 254) {
                cc[indexNum]++;
            }
            Color vv = new Color(cc[0], cc[1], cc[2]);
            list.add(vv);
        }
        return list.get(index % list.size());
    }
}
